package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("UserCartController")
@RequestMapping("/user/shoppingCart")
public class CartController {

    @Autowired
    private CartService cartService;

    @GetMapping("/list")
    public Result<List<ShoppingCart>> GetCart() {
        List<ShoppingCart> shoppingCart = cartService.CheckCart();
        return Result.success(shoppingCart);
    }

    @PostMapping("/add")
    public Result addCart(@RequestBody ShoppingCartDTO shoppingCartDTO){
        cartService.addcart(shoppingCartDTO);
        return Result.success();
    }

    @DeleteMapping("/clean")
    public Result cleanCart(){
        cartService.clearAll();
        return Result.success();
    }

    @PostMapping("sub")
    public Result subCart(@RequestBody ShoppingCartDTO shoppingCartDTO){
        cartService.subCart(shoppingCartDTO);
        return Result.success();
    }
}
